//
// Created by jsjxsy on 2022/8/17.
//
#include <iostream>
#include <cstdio>
using namespace std;
class Base {
 public:
  virtual ~Base() {
    cout << "~Base()" << endl;
  }
  virtual void say() {
    cout << "this is base class" << endl;
  }
};

class Derived : public Base {
 public:
  void say() {
    cout << "this is Derived class" << endl;
  }
  ~Derived() {
    cout << "~Derived()" << endl;
  }
};


int main() {
  Base *bp;
  bp = new Derived();
  if (Derived *dp = dynamic_cast<Derived *>(bp)) {
    puts("bp cast dp success");
    dp->say();
  } else {
    puts("bp cast dp fail");
  }
  delete bp;
  return 0;
}